home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.006 / xemacs-1 / lib / xemacs-19.13 / lisp / edebug / cl-read.el next >
Encoding:
Text File  |  1994-09-20  |  38.7 KB  |  1,145 lines

  1. ;;   -*- Mode: emacs-lisp -*-
  2. ;; 
  3. ;; Customizable, CL-like reader for version 19 Emacs Lisp. 
  4. ;; 
  5. ;; Copyright (C) 1993 by Guido Bosch <Guido.Bosch@loria.fr>
  6.  
  7. ;; This file is written in GNU Emacs Lisp, but not (yet) part of GNU Emacs.
  8.  
  9. ;; The software contained in this file is free software; you can
  10. ;; redistribute it and/or modify it under the terms of the GNU General
  11. ;; Public License as published by the Free Software Foundation; either
  12. ;; version 2, or (at your option) any later version.
  13.  
  14. ;; GNU Emacs is distributed in the hope that it will be useful,
  15. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. ;; GNU General Public License for more details.
  18.  
  19. ;; You should have received a copy of the GNU General Public License
  20.  
  21. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  22. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  23. ;; 
  24. ;; Please send bugs and comments to the author.
  25. ;;
  26. ;; <DISCLAIMER>
  27. ;; This program is still under development.  Neither the author nor
  28. ;; his employer accepts responsibility to anyone for the consequences of
  29. ;; using it or for whether it serves any particular purpose or works
  30. ;; at all.
  31.  
  32.  
  33. ;; Introduction
  34. ;; ------------
  35. ;;
  36. ;; This package replaces the standard Emacs Lisp reader (implemented
  37. ;; in C) by a flexible and customizable Common Lisp like one
  38. ;; (implemented entirely in Emacs Lisp). During reading of elisp
  39. ;; source files, it is about 50% slower than the built-in reader, but
  40. ;; there is no difference for byte compiled files - they dont contain
  41. ;; any syntactic sugar and are loaded with the built in subroutine
  42. ;; `load'.
  43.  
  44. ;; The user level functions for defining read tables, character and
  45. ;; dispatch macros are implemented according to the Commom Lisp
  46. ;; specification by Steels (2nd edition), but the macro functions
  47. ;; itself are implemented in a slightly different way, because the
  48. ;; character reading is done in an Emacs buffer, and not by using the
  49. ;; primitive funtions `read-char' and `unread-char', as a real CL
  50. ;; does.  To get 100% compatibility with CL, the above functions (or
  51. ;; their equivalents) have to be implemented as subroutines. 
  52.  
  53. ;; Another difference to real CL reading is that basic token (symbols
  54. ;; numbers, strings, and a few more) are still read by the
  55. ;; original elisp reader. This is necessary to get a reasonable
  56. ;; performance. As a consquence, the syntax of basic tokens can't be
  57. ;; customized.
  58.  
  59. ;; Most of the built-in character syntax has been replaced by lisp
  60. ;; character macros: parentheses and brackets, simple and double
  61. ;; quotes, semicolon comments and the dot. New syntax features are:
  62.  
  63. ;; Backquote-Comma-Atsign Macro: `(,el ,@list) 
  64. ;;
  65. ;; (the clumsy elisp syntax (` ((, el) (,@ list))) is also supported,
  66. ;; but with one restriction: the blank behind the quote characters is
  67. ;; mandatory for the old syntax. The cl reader needs it as a landmark
  68. ;; to distinguish between old and new syntax. An example:
  69. ;;
  70. ;; With blanks, both readers read the same:
  71. ;; (` (, (head)) (,@ (tail))) -std-read->  (` (, (head)) (,@ (tail)))
  72. ;; (` (, (head)) (,@ (tail))) -cl-read->   (` (, (head)) (,@ (tail)))
  73. ;;
  74. ;; Without blanks, the form is interpreted differently by the two readers:
  75. ;; (`(,(head)) (,@(tail))) -std-read-> (` (, (head)) (,@ (tail)))
  76. ;; (`(,(head)) (,@(tail))) -cl-read->  ((` ((, ((head)))) ((,@ ((tail)))))
  77. ;;
  78. ;; 
  79. ;; Dispatch Character Macro" `#'
  80. ;;
  81. ;; #'<function>            function quoting
  82. ;; #\<charcter>            character syntax
  83. ;; #.<form>                read time evaluation
  84. ;; #p<path>, #P<path>         paths
  85. ;; #+<feature>, #-<feature>     conditional reading
  86. ;; #<n>=, #<n>#         tags for shared structure reading
  87. ;;
  88. ;; Other read macros can be added easyly (see the definition of the
  89. ;; above ones in this file using the function `set-macro-character')
  90.  
  91. ;; The Cl reader is mostly downward compatile, (exception: backquote
  92. ;; comma macro, see above). E.g., this file, which is written entirely
  93. ;; in the old Emacs Lisp dialect, can be read and compiled with the
  94. ;; cl-reader being activated. 
  95.  
  96. ;; Installation: 
  97. ;; -------------
  98. ;;
  99. ;; The package is built on top of Dave Gillespie's cl.el package
  100. ;; (version 2.02 or later).  The old one (from Ceazar Quiroz, still
  101. ;; shiped with the Emacs 19 disributions) will not do.
  102. ;;
  103. ;; To use the cl-read package automatically when reading in a buffer, 
  104. ;; it has to be installed using the emacs-lisp-mode-hook:
  105. ;;
  106. ;; (add-hook 'emacs-lisp-mode-hook 'cl-read-install)
  107. ;;
  108. ;; (defun cl-read-install ()
  109. ;;   (save-excursion
  110. ;;     (goto-char (point-min))
  111. ;;     (let ((case-fold-search t))
  112. ;;       (cond ((re-search-forward 
  113. ;;               "read-syntax: *common-lisp" 
  114. ;;               (save-excursion 
  115. ;;                 (end-of-line)
  116. ;;                 (point))
  117. ;;               t)
  118. ;;              (require 'cl-read)
  119. ;;              (setq cl-read-active t))))))
  120. ;;
  121. ;; As most of the Emacs Lisp files are written
  122. ;; using the standard syntax, the cl reader is only loaded and
  123. ;; activated on elisp files with the "Read-Syntax" property set to
  124. ;; "Common-Lisp" (in the property line):
  125. ;;
  126. ;; -*- Read-Syntax: Common-Lisp -*-
  127. ;;
  128. ;; Note that both property name ("Read-Syntax") and value
  129. ;; ("Common-Lisp") are not case sensitive. There can also be other
  130. ;; properties in this line: 
  131. ;;
  132. ;; -*- Mode: Emacs-Lisp; Read-Syntax: Common-Lisp -*-
  133. ;;
  134. ;; The `cl-read-install' hook function tests for the presence of the
  135. ;; correct Read-Syntax property and loads the cl-read package if
  136. ;; necessary. This replaces the follwing standard elisp
  137. ;; functions:
  138. ;;
  139. ;;     - read
  140. ;;     - read-from-string
  141. ;;     - eval-current-buffer
  142. ;;     - eval-buffer
  143. ;;     - eval-region
  144. ;;
  145. ;; There may be other built-in functions that need to be replaced
  146. ;; (load, e.g).  The behavior of the new reader function depends on
  147. ;; the value of the buffer local variable `cl-read-active': if it is
  148. ;; nil, they just call the original functions, otherwise they call the
  149. ;; cl reader. If the cl reader is active in a buffer, the string "CL"
  150. ;; appears behind the mode name in the buffer's mode line.
  151. ;; 
  152. ;;
  153. ;; TO DO List: 
  154. ;; -----------
  155. ;; - Provide a replacement for load so that uncompiled cl syntax
  156. ;;   source file can be loaded, too.   - some have written load in elisp.
  157. ;; - Do we really need the (require 'cl) dependency? 
  158. ;; - More read macros.
  159. ;; - Refine the error signaling mechanism. 
  160.  
  161.  
  162. ; Change History
  163. ; !Log: cl-read.el,v !
  164. ; Revision 1.8  1993/08/10  13:43:34  bosch
  165. ; Hook function `cl-read-install' for automatic installation added.
  166. ; Buffer local variable `cl-read-active' added: together with the above
  167. ; hook it allows the file specific activation of the cl reader.
  168. ;
  169. ; Revision 1.7  1993/08/10  10:35:21  bosch
  170. ; Functions `read*' and `read-from-string*' renamed into `reader:read'
  171. ; and `reader:read-from-string'. Whitespace character skipping after
  172. ; recursive reader calls removed (Emacs 19 should not need this).
  173. ; Functions `cl-reader-install'  and `cl-reader-uninstall' updated.
  174. ; Introduction text and  function comments added.
  175. ;
  176. ; Revision 1.6 1993/08/09 15:36:05 bosch Function `read*' now nearly
  177. ; elisp compatible (no functions as streams, yet -- I don't think I
  178. ; will ever implement this, it would be far too slow).  Elisp
  179. ; compatible function `read-from-string*' added.  Replacements for
  180. ; `eval-current-buffer', `eval-buffer' and `eval-region' added.
  181. ; Renamed feature `cl-dg' in `cl', as Dave Gillespie's cl.el package
  182. ; is rather stable now.  Function `cl-reader-install' and
  183. ; `cl-reader-uninstall' modified.
  184. ;
  185. ; Revision 1.5  1993/08/09  10:23:35  bosch
  186. ; Functions `copy-readtable' and `set-syntax-from-character' added.
  187. ; Variable `reader:internal-standard-readtable' added.  Standard
  188. ; readtable initialization modified. Whitespace skipping placed back
  189. ; inside the read loop.
  190. ;
  191. ; Revision 1.4  1993/05/14  13:00:48  bosch
  192. ; Included patches from Daniel LaLiberte.
  193. ;
  194. ; Revision 1.3  1993/05/11  09:57:39  bosch
  195. ; `read*' renamed in `reader:read-from-buffer'. `read*' now can read
  196. ; from strings.
  197. ;
  198. ; Revision 1.2  1993/05/09  16:30:50  bosch
  199. ; (require 'cl-read) added.
  200. ; Calling of `{before,after}-read-hook' modified.
  201. ;
  202. ; Revision 1.1  1993/03/29  19:37:21  bosch
  203. ; Initial revision
  204. ;
  205. ;
  206.  
  207. (require 'cl)
  208. (provide 'cl-read)
  209. ;; load before compiling
  210. ;(require 'cl-read)
  211.  
  212. (autoload 'compiled-function-p "bytecomp")
  213.  
  214. (defvar cl-read-active nil
  215.   "Buffer local variable that enables Common Lisp style syntax reading.")
  216. (make-variable-buffer-local 'cl-read-active)
  217. (setq-default cl-read-active nil)
  218.  
  219. (or (assq 'cl-read-active minor-mode-alist)
  220.     (setq minor-mode-alist
  221.       (cons '(cl-read-active " CL") minor-mode-alist)))
  222.  
  223.  
  224. ;; The readtable
  225.  
  226. (defvar reader:readtable-size 256
  227.   "The size of a readtable."
  228.   ;; Actually, the readtable is a vector of size (1+
  229.   ;; reader:readtable-size), because the last element contains the
  230.   ;; symbol `readtable', used for defining `readtablep.
  231.   )
  232.  
  233. ;; An entry of the readtable must have one of the following forms:
  234. ;;
  235. ;; 1. A symbol, one of {illegal, constituent, whitespace}.  It means 
  236. ;;    the character's reader class.
  237. ;;
  238. ;; 2. A function (i.e., a symbol with a function definition, a byte
  239. ;;    compiled function or an uncompiled lambda expression).  It means the
  240. ;;    character is a macro character.
  241. ;;
  242. ;; 3. A vector of length `reader:readtable-size'. Elements of this vector
  243. ;;    may be `nil' or a function (see 2.). It means the charater is a
  244. ;;    dispatch character, and the vector its dispatch fucntion table.
  245.  
  246. (defun* copy-readtable 
  247.     (&optional (from-readtable *readtable*) 
  248.            (to-readtable 
  249.         (make-vector (1+ reader:readtable-size) 'illegal)))
  250.   "Return a copy of FROM-READTABLE \(default: *readtable*\). If the
  251. FROM-READTABLE argument is provided as `nil', make a copy of a
  252. standard \(CL-like\) readtable. If TO-READTABLE is provided, modify and
  253. return it, otherwise create a new readtable object."
  254.  
  255.   (if (null from-readtable)
  256.       (setq from-readtable reader:internal-standard-readtable))
  257.  
  258.   (loop for i to reader:readtable-size
  259.     as from-syntax = (aref from-readtable i)
  260.     do (setf (aref to-readtable i)
  261.          (if (vectorp from-syntax)
  262.              (copy-sequence from-syntax)
  263.            from-syntax))
  264.     finally return to-readtable))
  265.  
  266.  
  267. (defmacro reader:get-readtable-entry (char readtable)
  268.   (` (aref (, readtable) (, char))))
  269.    
  270. (defun set-macro-character 
  271.   (char function &optional readtable)
  272.     "Makes CHAR to be a macro character with FUNCTION as handler.
  273. When CHAR is seen by reader:read-from-buffer, it calls FUNCTION.
  274. Returns always t. Optional argument READTABLE is the readtable to set
  275. the macro character in (default: *readtable*)."
  276.   (or readtable (setq readtable *readtable*))
  277.   (or (reader:functionp function) 
  278.       (error "Not valid character macro function: %s" function)) 
  279.   (setf (reader:get-readtable-entry char readtable) function)
  280.   t)
  281.  
  282.  
  283. (put 'set-macro-character 'edebug-form-spec 
  284.      '(&define sexp function-form &optional sexp))
  285. (put 'set-macro-character 'lisp-indent-function 1)
  286.  
  287. (defun get-macro-character (char &optional readtable)
  288.    "Return the function associated with the character CHAR in READTABLE
  289. \(default: *readtable*.\). If char isn't a macro charater in
  290. READTABLE, return nil."
  291.    (or readtable (setq readtable *readtable*))
  292.    (let ((entry (reader:get-readtable-entry char readtable)))
  293.      (if (reader:functionp entry) 
  294.      entry)))
  295.  
  296. (defun set-syntax-from-character 
  297.   (to-char from-char &optional to-readtable from-readtable)   
  298.   "Make the syntax of TO-CHAR be the same as the syntax of FROM-CHAR.
  299. Optional TO-READTABLE and FROM-READTABLE are the corresponding tables
  300. to use. TO-READTABLE defaults to the current readtable
  301. \(*readtable*\), and FROM-READTABLE to nil, meaning to use the
  302. syntaxes from the standard Lisp Readtable."
  303.   (or to-readtable (setq to-readtable *readtable*))
  304.   (or from-readtable 
  305.       (setq from-readtable reader:internal-standard-readtable))
  306.   (let ((from-syntax
  307.      (reader:get-readtable-entry from-char from-readtable)))
  308.     (if (vectorp from-syntax)
  309.     ;; dispatch macro character table
  310.     (setq from-syntax (copy-sequence from-syntax)))
  311.     (setf (reader:get-readtable-entry to-char to-readtable)
  312.       from-syntax))
  313.   t)
  314.  
  315.  
  316. ;; Dispatch macro character
  317. (defun make-dispatch-macro-character (char &optional readtable)
  318.   "Let CHAR be a dispatch macro character in READTABLE (default: *readtable*)."
  319.   (or readtable (setq readtable *readtable*))
  320.   (setf (reader:get-readtable-entry char readtable)
  321.     ;; create a dispatch character table 
  322.     (make-vector reader:readtable-size nil)))
  323.  
  324.  
  325. (defun set-dispatch-macro-character 
  326.   (disp-char sub-char function &optional readtable)
  327.   "Make reading CHAR1 followed by CHAR2 be handled by FUNCTION.
  328. Optional argument READTABLE (default: *readtable*).  CHAR1 must first be 
  329. made a dispatch char with `make-dispatch-macro-character'."
  330.   (or readtable (setq readtable *readtable*))
  331.   (let ((disp-table (reader:get-readtable-entry disp-char readtable)))
  332.     ;; check whether disp-char is a valid dispatch character
  333.     (or (vectorp disp-table)
  334.     (error "`%c' not a dispatch macro character." disp-char))
  335.     ;; check whether function is a valid function 
  336.     (or (reader:functionp function) 
  337.     (error "Not valid dispatch character macro function: %s" function))
  338.     (setf (aref disp-table sub-char) function)))
  339.  
  340.  
  341. (put 'set-dispatch-macro-character 'edebug-form-spec
  342.      '(&define sexp sexp function-form &optional def-form))
  343. (put 'set-dispatch-macro-character 'lisp-indent-function 2)
  344.  
  345.  
  346. (defun get-dispatch-macro-character (disp-char sub-char &optional readtable)
  347.   "Return the macro character function for SUB-CHAR unser DISP-CHAR in
  348. READTABLE (default: *readtable*), or nil if there is no such
  349. function."
  350.   (or readtable (setq readtable *readtable*))
  351.   (let ((disp-table (reader:get-readtable-entry disp-char readtable)))
  352.     (and (vectorp disp-table)
  353.      (reader:functionp (aref disp-table sub-char))
  354.      (aref disp-table sub-char))))
  355.  
  356.  
  357. (defun reader:functionp (function)
  358.   "Check whether FUNCTION is a valid function object to be used 
  359. as (dispatch) macro character function."
  360.   (or (and (symbolp function) (fboundp function))
  361.       (compiled-function-p function)
  362.       (and (consp function) (eq (first function) 'lambda))))
  363.        
  364.  
  365. ;; The basic reader loop 
  366.  
  367. ;; shared and circular structure reading
  368. (defvar reader:shared-structure-references nil)
  369. (defvar reader:shared-structure-labels nil)
  370.  
  371.  
  372. (defconst before-read-hook nil)
  373. (defconst after-read-hook nil)
  374.  
  375. ;; Set the hooks to `read-char' in order to step through the reader:
  376. ;; (add-hook 'before-read-hook '(lambda () (message "before") (read-char)))
  377. ;; (add-hook 'after-read-hook '(lambda () (message "after") (read-char)))
  378.    
  379. ;; *** Documenting internal things is fine, but you should probably leave
  380. ;; them as comments to save space.
  381.  
  382. (defmacro reader:encapsulate-recursive-call (reader-call)
  383.   "Encapsulate READER-CALL, a form that contains a recursive call to the
  384. reader, for usage inside the main reader loop.  The macro wraps two
  385. hooks around READER-CALL: `before-read-hook' and `after-read-hook'. 
  386.  
  387. If READER-CALL returns normally, the macro exits immediately from the
  388. surrounding loop with the value of READER-CALL as result.  If it exits
  389. non-locally (with tag `reader-ignore'), it just returns the value of
  390. READER-CALL, in which case the surrounding reader loop continues its
  391. execution.
  392.  
  393. In both cases, `before-read-hook' and `after-read-hook' are called
  394. before and after executing READER-CALL."
  395.  
  396.   (` (prog2
  397.      (run-hooks 'before-read-hook)
  398.      ;; this catch allows to ignore the return, in the case that reader:read-from-buffer
  399.      ;; should continue looping (e.g. skipping over comments)
  400.      (catch 'reader-ignore
  401.        ;; this only works inside a block (e.g., in a loop): 
  402.        ;; go outside 
  403.        (return 
  404.         (prog1 
  405.         (, reader-call)
  406.           ;; this occurence of the after hook fires if the 
  407.           ;; reader-call returns normally ...
  408.           (run-hooks 'after-read-hook))))
  409.        ;; ... and that one if  it was thrown to the tag 'reader-ignore
  410.        (run-hooks 'after-read-hook))))
  411.  
  412. (defvar reader:tmp-buffer
  413.   (get-buffer-create " *CL Read*"))
  414.  
  415. ;; save a pointer to the original `read-from-string' function
  416. (or (fboundp 'reader:original-read-from-string)
  417.     (fset 'reader:original-read-from-string
  418.       (symbol-function 'read-from-string)))
  419.  
  420. (defun reader:read-from-string (string &optional start end)
  421.   "Read one Lisp expression which is represented as text by STRING.
  422. Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX).
  423. START and END optionally delimit a substring of STRING from which to read;
  424.  they default to 0 and (length STRING) respectively.
  425.  
  426. This is the cl-read replacement of the standard elisp function
  427. `read-from-string'."
  428.  
  429.   ;; It doesnt really make sense to have read-from-string depend on
  430.   ;; what the current buffer happens to be.
  431.   (if nil ;; (not cl-read-active)
  432.       (reader:original-read-from-string string start end)
  433.     (or start (setq start 0))
  434.     (or end (setq end (length string)))
  435.     (save-excursion
  436.       (set-buffer reader:tmp-buffer)
  437.       (auto-save-mode -1)
  438.       (erase-buffer)
  439.       (insert (substring string 0 end))
  440.       (goto-char (1+ start))
  441.       (cons 
  442.        (reader:read-from-buffer reader:tmp-buffer nil)
  443.        (1- (point))))))
  444.  
  445. ;; (read-from-string "abc (car 'a) bc" 4)
  446. ;; (reader:read-from-string "abc (car 'a) bc" 4)
  447. ;; (read-from-string "abc (car 'a) bc" 2 11)
  448. ;; (reader:read-from-string "abc (car 'a) bc" 2 11)
  449. ;; (reader:read-from-string "`(car ,first ,@rest)")
  450. ;; (read-from-string ";`(car ,first ,@rest)")
  451. ;; (reader:read-from-string ";`(car ,first ,@rest)")
  452.  
  453.  
  454. ;; save a pointer to the original read function
  455. (or (fboundp 'reader:original-read)
  456.     (fset 'reader:original-read  (symbol-function 'read)))
  457.  
  458. (defun reader:read (&optional stream recursive-p)
  459.   "Read one Lisp expression as text from STREAM, return as Lisp object.
  460. If STREAM is nil, use the value of `standard-input' \(which see\).
  461. STREAM or the value of `standard-input' may be:
  462.  a buffer \(read from point and advance it\)
  463.  a marker \(read from where it points and advance it\)
  464.  a string \(takes text from string, starting at the beginning\)
  465.  t \(read text line using minibuffer and use it\).
  466.  
  467. This is the cl-read replacement of the standard elisp function
  468. `read'. The only incompatibility is that functions as stream arguments
  469. are not supported."
  470.   (if (not cl-read-active)
  471.       (reader:original-read stream)
  472.     (if (null stream)            ; read from standard-input
  473.     (setq stream standard-input))
  474.  
  475.     (if (eq stream 't)            ; read from minibuffer
  476.     (setq stream (read-from-minibuffer "Common Lisp Expression: ")))
  477.  
  478.     (cond 
  479.  
  480.      ((bufferp stream)            ; read from buffer
  481.       (reader:read-from-buffer stream recursive-p))
  482.  
  483.      ((markerp stream)            ; read from marker
  484.       (save-excursion 
  485.     (set-buffer (marker-buffer stream))
  486.     (goto-char (marker-position stream))
  487.     (reader:read-from-buffer (current-buffer) recursive-p)))
  488.  
  489.      ((stringp stream)            ; read from string
  490.       (save-excursion
  491.     (set-buffer reader:tmp-buffer)
  492.     (auto-save-mode -1)
  493.     (erase-buffer)
  494.     (insert stream)
  495.     (goto-char (point-min))
  496.     (reader:read-from-buffer reader:tmp-buffer recursive-p)))
  497.      (t 
  498.       (error "CL reader error: Not a valid stream: %s"
  499.          stream)))))
  500.  
  501. ;; (reader:read "#'car")
  502. ;; (read)
  503. ;; (reader:read)
  504. ;; (let ((standard-input nil)) (reader:read))
  505. ;; (reader:read (current-buffer))  'hello
  506. ;; (reader:read (save-excursion (backward-sexp 1) (point-marker)))
  507.  
  508. (defun reader:read-from-buffer (&optional stream recursive-p)
  509.   (or (bufferp stream)
  510.       (error "Sorry, can only read on buffers"))
  511.   (if (not recursive-p)
  512.       (let (reader:shared-structure-references
  513.         reader:shared-structure-labels)
  514.     (reader:restore-shared-structure
  515.      (reader:read-from-buffer stream 't)))
  516.  
  517.     (loop for char = (following-char)
  518.       for entry = (reader:get-readtable-entry  char *readtable*)
  519.       if (eobp) do (error "CL read error: End of file during reading")
  520.       do 
  521.       (cond 
  522.  
  523.        ((eq entry 'illegal)
  524.         (error "CL read error: `%c' has illegal character syntax" char))
  525.  
  526.        ;; skipping whitespace characters must be done inside this
  527.        ;; loop as character macro subroutines may return without
  528.        ;; leaving the loop using (throw 'reader-ignore ...)
  529.        ((eq entry 'whitespace)
  530.         (forward-char 1)  
  531.         ;; skip all whitespace
  532.         (while (eq 'whitespace 
  533.                (reader:get-readtable-entry  
  534.             (following-char) *readtable*))
  535.           (forward-char 1)))
  536.  
  537.        ;; for every token starting with a constituent character
  538.        ;; call the built-in reader (symbols, numbers, strings,
  539.        ;; characters with ?<char> syntax)
  540.        ((eq entry 'constituent)    
  541.         (reader:encapsulate-recursive-call
  542.          (reader:read-constituent stream)))
  543.  
  544.        ((vectorp entry)
  545.         ;; Dispatch macro character. The dispatch macro character
  546.         ;; function is contained in the vector `entry', at the
  547.         ;; place indicated by <sub-char>, the first non-digit
  548.         ;; character following the <disp-char>:
  549.         ;;     <disp-char><digit>*<sub-char>
  550.         (reader:encapsulate-recursive-call
  551.           (loop initially do (forward-char 1)
  552.             for sub-char = (prog1 (following-char) 
  553.                      (forward-char 1))
  554.             while (memq sub-char 
  555.                 '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9))
  556.             collect sub-char into digit-args
  557.             finally 
  558.             (return 
  559.              (funcall 
  560.               ;; no test is done here whether a non-nil
  561.               ;; contents is a correct dispatch character
  562.               ;; function to apply.
  563.               (or (aref entry sub-char)
  564.               (error 
  565.                "Cl reader error: undefined subsequent dispatch \
  566. character `%c'" sub-char))
  567.               stream
  568.               sub-char 
  569.               (string-to-int
  570.                (apply 'concat 
  571.                   (mapcar 
  572.                    'char-to-string digit-args))))))))
  573.         
  574.        (t
  575.         ;; must be a macro character. In this case, `entry' is
  576.         ;; the function to be called
  577.         (reader:encapsulate-recursive-call
  578.           (progn 
  579.         (forward-char 1)
  580.         (funcall entry stream char))))))))
  581. ;; ?\"   
  582. ;; '[aaaa  (a . b)  bbbb]  `(a ,b ,@l) (` a (, b) (,@ l))
  583.  
  584.  
  585. (put 'reader:encapsulate-recursive-call 'edebug-form-spec '(form))
  586. (put 'reader:encapsulate-recursive-call 'lisp-indent-function 0)
  587.  
  588.  
  589. '(defun reader:read-constituent (stream)
  590.   ;; For Emacs 19, just read it.
  591.   (reader:original-read stream))
  592.  
  593. (defun reader:read-constituent (stream)
  594.   (prog1 (reader:original-read stream)
  595. ;;; For Emacs 18, backing up is necessary because the `read'
  596. ;;; function reads one character too far after reading a symbol or number.
  597. ;;; This doesnt apply to reading chars (e.g. ?n).
  598.     ;; This still loses for escaped chars.
  599.     (if (not (eq (reader:get-readtable-entry
  600.           (preceding-char) *readtable*) 'constituent))
  601.     (forward-char -1))))
  602.  
  603.  
  604.  
  605. ;; Creation and initialization of an internal standard readtable. 
  606.  
  607. (defconst  reader:internal-standard-readtable
  608.   (loop with raw-readtable = 
  609.     (make-vector (1+ reader:readtable-size) 'illegal)
  610.     initially do (setf (aref raw-readtable reader:readtable-size)
  611.                'readtable)
  612.     for entry in 
  613.     '((constituent ?! ?@ ?$ ?% ?& ?* ?_ ?- ?+ ?= ?/ ?\\ ?0 ?1 ?2
  614.                ?3 ?4 ?5 ?6 ?7 ?8 ?9 ?: ?~ ?> ?< ?a ?b
  615.                ?c ?d ?e ?f ?g ?h ?i ?j ?k ?l ?m ?n ?o ?p
  616.                ?q ?r ?s ?t ?u ?v ?w ?x ?y ?z ?A ?B ?C ?D
  617.                ?E ?F ?G ?H ?I ?J ?K ?L ?M ?N ?O ?P ?Q ?R
  618.                ?S ?T ?U ?V ?W ?X ?Y ?Z)
  619.       (whitespace ?  ?\t ?\n ?\r ?\f)
  620.  
  621.       ;; The following CL character classes are only useful for
  622.       ;; token parsing.  We don't need them, as token parsing is
  623.       ;; left to the built-in reader.
  624.       ;; (single-escape ?\\)
  625.       ;; (multiple-escape ?|)
  626.       )
  627.     do 
  628.     (loop for char in (rest entry)
  629.           do (setf (reader:get-readtable-entry  char raw-readtable)
  630.                (first entry)))
  631.     finally return raw-readtable)
  632.   "The original (CL-like) standard readtable. If you ever modify this
  633. readtable, you won't be able to recover a standard readtable using
  634. \(copy-readtable nil\)")
  635.  
  636.  
  637. ;; Variables used non-locally in the standard readmacros
  638. (defvar reader:context)
  639. (defvar reader:stack)
  640. (defvar recursive-p)  ; need reader: prefix.
  641.  
  642. ;; Changing the setting for a char here needs to be done
  643. ;; for both the internal standard readtable and the *readtable*.
  644. ;; Is (set-syntax-from-character char char *readtable*) sufficient?
  645. ;; Could we instead set-macro-character for *readtable* in the source below,
  646. ;; and then copy *readtable* to reader:internal-standard-readtable?
  647.  
  648. ;; Chars and strings
  649.  
  650. ;; This is defined to distinguish chars from constituents 
  651. ;; since chars read without reading too far.
  652. (set-macro-character ?\?
  653.   (function
  654.    (lambda (stream char)
  655.      (forward-char -1)
  656.      (reader:original-read stream)))
  657.   reader:internal-standard-readtable)
  658.  
  659. ;; This is defined to distinguish strings from constituents
  660. ;; since backing up after reading a string is simpler.
  661. (set-macro-character ?\"
  662.   (function
  663.    (lambda (stream char)
  664.      (forward-char -1)
  665.      (prog1 (reader:original-read stream)
  666.        ;; This is not needed with Emacs 19.  See above.
  667.        (if (/= (preceding-char) ?\")
  668.        (forward-char -1)))))
  669.   reader:internal-standard-readtable)
  670.  
  671. ;; Lists and dotted pairs
  672. (set-macro-character ?\( 
  673.   (function 
  674.    (lambda (stream char)
  675.      (catch 'read-list
  676.        (let ((reader:context 'list) reader:stack )
  677.      ;; read list elements up to a `.'
  678.      (catch 'dotted-pair
  679.        (while t
  680.          (setq reader:stack (cons (reader:read-from-buffer stream 't) 
  681.                       reader:stack))))
  682.      ;; In dotted pair. Read one more element
  683.      (setq reader:stack (cons (reader:read-from-buffer stream 't) 
  684.                   reader:stack)
  685.            ;; signal it to the closing paren
  686.            reader:context 'dotted-pair)
  687.      ;; this *must* be the closing paren that throws away from here
  688.      (reader:read-from-buffer stream 't)
  689.      ;; otherwise an error is signalled
  690.      (error "illegal dotted pair read syntax")))))
  691.   reader:internal-standard-readtable)
  692.  
  693. (set-macro-character ?\) 
  694.   (function 
  695.    (lambda (stream char)
  696.      (cond ((eq reader:context 'list)
  697.         (throw 'read-list (nreverse reader:stack)))
  698.        ((eq reader:context 'dotted-pair)
  699.         ;(throw 'read-list (apply 'list* (nreverse reader:stack)))
  700.         (throw 'read-list (nconc (nreverse (cdr reader:stack)) 
  701.                      (car reader:stack)))
  702.         )
  703.        (t 
  704.         (error "CL read error: `)' doesn't end a list")))))
  705.   reader:internal-standard-readtable)
  706.     
  707. (set-macro-character ?\.
  708.   (function 
  709.    (lambda (stream char)
  710.      (and (eq reader:context 'dotted-pair) 
  711.       (error "CL read error: no more than one `.' allowed in list"))
  712.      (throw 'dotted-pair nil)))
  713.   reader:internal-standard-readtable)
  714.  
  715. ;; '(#\a . #\b)
  716. ;; '(a . (b . c))
  717.  
  718. ;; Vectors: [a b]
  719. (set-macro-character ?\[
  720.   (function
  721.    (lambda (stream char)
  722.      (let ((reader:context 'vector))
  723.        (catch 'read-vector
  724.      (let ((reader:context 'vector)
  725.            reader:stack)
  726.        (while t (push (reader:read-from-buffer stream 't)
  727.               reader:stack)))))))
  728.   reader:internal-standard-readtable) 
  729.  
  730. (set-macro-character ?\] 
  731.   (function 
  732.    (lambda (stream char)
  733.      (if (eq reader:context 'vector)
  734.      (throw 'read-vector (apply 'vector (nreverse reader:stack)))
  735.        (error "CL read error: `]' doesn't end a vector"))))
  736.   reader:internal-standard-readtable) 
  737.  
  738.  
  739. ;; Quote and backquote comma macro
  740. (set-macro-character ?\'
  741.   (function
  742.    (lambda (stream char)
  743.      (list 'quote (reader:read-from-buffer stream 't))))
  744.   reader:internal-standard-readtable)
  745.  
  746. (set-macro-character ?\`
  747.   (function
  748.    (lambda (stream char)
  749.      (if (= (following-char) ?\ )
  750.      ;; old backquote syntax. This is ambigous, because 
  751.      ;; (`(sexp)) is a valid form in both syntaxes, but 
  752.      ;; unfortunately not the same. 
  753.      ;; old syntax: read -> (` (sexp))
  754.      ;; new syntax: read -> ((` (sexp)))
  755.      '\`
  756.        (list '\` (reader:read-from-buffer stream 't)))))
  757.   reader:internal-standard-readtable)
  758.  
  759. (set-macro-character ?\,
  760.   (function
  761.    (lambda (stream char)
  762.      (cond ((eq (following-char) ?\ )
  763.         ;; old syntax
  764.         '\,)
  765.        ((eq (following-char) ?\@)
  766.         (forward-char 1)
  767.         (cond ((eq (following-char) ?\ )
  768.            '\,\@)
  769.           ((list '\,\@ (reader:read-from-buffer stream 't)))))
  770.        ((list '\, (reader:read-from-buffer stream 't))))))
  771.   reader:internal-standard-readtable)
  772. ;; 'a '(a b c)
  773. ;; `(,a ,@b c)  
  774. ;; the old syntax is also supported:
  775. ;; (` ((, a) (,@ b) c))    
  776.  
  777. ;; Single character comment:  ; 
  778. (set-macro-character ?\;
  779.   (function
  780.    (lambda (stream char)
  781.      (skip-chars-forward "^\n\r")
  782.      (throw 'reader-ignore nil)))
  783.   reader:internal-standard-readtable)
  784.  
  785. ;; Standard CL dispatch character #
  786. (make-dispatch-macro-character ?\# reader:internal-standard-readtable)
  787.  
  788. ;; Function quoting: #'<function>
  789. (set-dispatch-macro-character ?\# ?\'
  790.   (function
  791.    (lambda (stream char n)
  792.      (or (= n 0) 
  793.      (error
  794.       "Cl reader error: numeric infix argument not allowed %d" n))
  795.      (list (if (featurep 'cl)  'function* 'function)
  796.        (reader:read-from-buffer stream 't))))
  797.   reader:internal-standard-readtable)
  798.  
  799. ;; Character syntax: #\<char> 
  800. ;; Not yet implemented: #\Control-a #\M-C-a etc. 
  801. (set-dispatch-macro-character ?# ?\\
  802.   (function 
  803.    (lambda (stream char n)
  804.      (or (= n 0) 
  805.      (error 
  806.       "Cl reader error: numeric infix argument not allowed %d" n))
  807.      (let ((next (following-char))
  808.        name)
  809.        (if (not (and (<= ?a next) (<= next ?z)))
  810.        (progn (forward-char 1) next)
  811.      (setq next (reader:read-from-buffer stream t))
  812.      (cond ((symbolp next) (setq name (symbol-name next)))
  813.            ((integerp next) (setq name (int-to-string next))))
  814.      (if (= 1 (length name))
  815.          (string-to-char name)
  816.        (case next
  817.          (linefeed    ?\n)
  818.          (newline    ?\r)
  819.          (space    ?\ )
  820.          (rubout    ?\b)
  821.          (page    ?\f)
  822.          (tab       ?\t)
  823.          (return    ?\C-m)
  824.          (t
  825.           (error
  826.            "CL read error: unknown character specification `%s'"
  827.            next))))))))
  828.   reader:internal-standard-readtable)
  829. ;; '(#\# #\> #\< #\a #\A #\tab #\return #\space)
  830.  
  831.  
  832. ;; Read and load time evaluation:  #.<form>
  833. ;; Not yet implemented: #,<form>
  834. (set-dispatch-macro-character ?\# ?\.
  835.   (function 
  836.    (lambda (stream char n)
  837.      (or (= n 0) 
  838.      (error 
  839.       "Cl reader error: numeric infix argument not allowed %d" n))
  840.      ;; This eval will see all internal vars of reader, 
  841.      ;; e.g. stream, recursive-p.  Anything that might be bound.
  842.      (eval (reader:read-from-buffer stream t))))
  843.   reader:internal-standard-readtable)
  844. ;; '(#.(current-buffer) #.(get-buffer "*scratch*"))
  845.  
  846. ;; Path names (kind of):  #p<string>, #P<string>,
  847. (set-dispatch-macro-character ?\# ?\P
  848.   (function 
  849.    (lambda (stream char n)
  850.      (or (= n 0) 
  851.      (error 
  852.       "Cl reader error: numeric infix argument not allowed %d" n))
  853.      (let ((string (reader:read-from-buffer stream 't)))
  854.        (or (stringp string) 
  855.        (error "Cl reader error: Pathname must be a string: %s" string))
  856.        (expand-file-name string))))
  857.   reader:internal-standard-readtable)
  858.  
  859. (set-dispatch-macro-character ?\# ?\p
  860.   (get-dispatch-macro-character ?\# ?\P reader:internal-standard-readtable)
  861.   reader:internal-standard-readtable)
  862.  
  863. ;; #P"~/.emacs"
  864. ;; #p"~root/home" 
  865.  
  866. ;; Feature reading:  #+<feature>,  #-<feature>
  867. ;; Not yet implemented: #+<boolean expression>, #-<boolean expression>
  868.  
  869. (set-dispatch-macro-character ?\# ?\+
  870.   (function 
  871.    (lambda (stream char n)
  872.      (or (= n 0) 
  873.      (error 
  874.       "Cl reader error: numeric infix argument not allowed %d" n))
  875.      (let ((feature (reader:read-from-buffer stream 't))
  876.        (object (reader:read-from-buffer stream 't)))
  877.        (if (featurep feature)
  878.        object
  879.      (throw 'reader-ignore nil)))))
  880.   reader:internal-standard-readtable)
  881.  
  882. (set-dispatch-macro-character ?\# ?\-
  883.   (function 
  884.    (lambda (stream char n)
  885.      (or (= n 0) 
  886.      (error 
  887.       "Cl reader error: numeric infix argument not allowed %d" n))
  888.      (let ((feature (reader:read-from-buffer stream 't))
  889.        (object (reader:read-from-buffer stream 't)))
  890.        (if (featurep feature)
  891.        (throw 'reader-ignore nil)
  892.      object))))
  893.   reader:internal-standard-readtable)
  894.  
  895. ;; (#+cl loop #+cl do #-cl while #-cl t (body))
  896.  
  897.  
  898. ;; Circular and shared structure reading: #<n>=, #<n>#
  899. (set-dispatch-macro-character ?\# ?\=
  900.   (function 
  901.    (lambda (stream char n)
  902.      (if (memq n reader:shared-structure-labels)
  903.      (error "Cl reader error: label defined twice")
  904.        (push n reader:shared-structure-labels))
  905.      (let* ((string (int-to-string n))
  906.         (ref (or (find string reader:shared-structure-references
  907.                :test 'string=)
  908.              (first 
  909.               (push (make-symbol string) 
  910.                 reader:shared-structure-references)))))
  911.      
  912.        (setf (symbol-value ref) 
  913.          ;; this is also the return value 
  914.          (reader:read-from-buffer stream 't)))))
  915.   reader:internal-standard-readtable)
  916.  
  917.  
  918. (set-dispatch-macro-character ?\# ?\#
  919.   (function
  920.    (lambda (stream char n)
  921.      ;; using the non-local variable `recursive-p' (from the reader
  922.      ;; main loop) doesn't seems very clever. Should do this
  923.      ;; differently ...
  924.      (if (not recursive-p)
  925.      (error "Cl reader error: references at top level not allowed"))
  926.      (let* ((string (int-to-string n))
  927.         (ref (or (find string reader:shared-structure-references
  928.                :test 'string=)
  929.              (first
  930.               (push (make-symbol string) 
  931.                 reader:shared-structure-references)))))
  932.        ;; the value of reading a #n# form is a reference symbol
  933.        ;; whose symbol value will be the shared structure
  934.        ref)))
  935.   reader:internal-standard-readtable)
  936.  
  937. (defun reader:restore-shared-structure (obj)
  938.   (cond 
  939.    ((consp obj)
  940.     (if (memq (car obj) reader:shared-structure-references)
  941.     (setf (car obj) (symbol-value (car obj)))
  942.       (reader:restore-shared-structure (car obj)))
  943.     (if (memq (cdr obj) reader:shared-structure-references)
  944.     (setf (cdr obj) (symbol-value (cdr obj)))
  945.       (reader:restore-shared-structure (cdr obj))))
  946.     
  947.    ((vectorp obj)
  948.     (loop for i below (length obj)
  949.       do
  950.       (if;; substructure  is a reference
  951.           (memq (aref obj i) reader:shared-structure-references)
  952.           ;; replace it by the pointer in the cdr of the ref
  953.           (setf (aref obj i) (symbol-value (aref obj i)))
  954.         (reader:restore-shared-structure (aref obj i))))))
  955.   obj)
  956.  
  957.  
  958. ;; #1=(a b #3=[#2=c])
  959. ;; (#1=[#\return #\a] #1# #1#)
  960. ;; (#1=[a b c] #1# #1#)
  961. ;; #1=(a b . #1#)
  962.  
  963. ;; Now make the current readtable
  964. (defvar *readtable* (copy-readtable nil)
  965.   "The current readtable.")
  966.  
  967.  
  968. ;; Replace built-in functions that call the (built-in) reader: 
  969.  
  970. (or (fboundp 'reader:original-eval-current-buffer)
  971.     (fset 'reader:original-eval-current-buffer 
  972.       (symbol-function 'eval-current-buffer)))
  973.     
  974. (defun reader:eval-current-buffer (&optional printflag)
  975.   "Evaluate the current buffer as Lisp code.
  976. Programs can pass argument PRINTFLAG which controls printing of output:
  977. nil means discard it\; anything else is stream for print.
  978.  
  979. This is the cl-read replacement of the standard elisp function
  980. `eval-current-buffer'."
  981.  
  982.   ;; The standard eval-current-buffer doesn't use eval-region.
  983.   (interactive)
  984.   (if (not cl-read-active)
  985.       (reader:original-eval-current-buffer printflag)
  986.     (reader:eval-buffer (current-buffer))))
  987.  
  988. (or (fboundp 'reader:original-eval-buffer)
  989.     (fset 'reader:original-eval-buffer 
  990.       (if (fboundp 'eval-buffer)  ;; only in Emacs 19.
  991.           (symbol-function 'eval-buffer)
  992.         'eval-buffer)))
  993.  
  994. (defun reader:eval-buffer (bufname &optional printflag)
  995.   "Execute BUFFER as Lisp code.  Programs can pass argument PRINTFLAG
  996. which controls printing of output: nil means discard it; anything else
  997. is stream for print.
  998.  
  999. This is the cl-read replacement of the standard elisp function
  1000. `eval-buffer'."
  1001.   (interactive "bBuffer: ")
  1002.   (if (not cl-read-active)
  1003.       (reader:original-eval-buffer bufname printflag)
  1004.     (save-excursion
  1005.       (set-buffer (or (get-buffer bufname) 
  1006.               (error "No such buffer: %s" bufname)))
  1007.       (reader:eval-region (point-min) (point-max) printflag))))
  1008.  
  1009. (or (fboundp 'reader:original-eval-region)
  1010.     (fset 'reader:original-eval-region 
  1011.       (symbol-function 'eval-region)))
  1012.  
  1013. ;; (borrowed from Daniel LaLiberte's edebug)
  1014. (defun reader:eval-region (start end &optional output)
  1015.   "Execute the region as Lisp code.
  1016. When called from programs, expects two arguments,
  1017. giving starting and ending indices in the current buffer
  1018. of the text to be executed.
  1019. Programs can pass third argument PRINTFLAG which controls output:
  1020. nil means discard it; anything else is stream for printing it.
  1021.  
  1022. If there is no error, point does not move.  If there is an error,
  1023. point remains at the end of the last character read from the buffer.
  1024.  
  1025. arguments: (b e &optional printflag)
  1026.  
  1027. This is the cl-read replacement of the standard elisp function
  1028. `eval-region'."
  1029.  
  1030.   ;; One other difference concerns inserting whitespace after the expression.
  1031.   (interactive "r")
  1032.   (if (not cl-read-active)
  1033.       (reader:original-eval-region start end output)
  1034.     (let ((pnt (point))
  1035.       (buf (current-buffer))
  1036.       (inside-buf (current-buffer))
  1037.       ;; Mark the end because it may move.
  1038.       (end-marker (set-marker (make-marker) end))
  1039.       form
  1040.       val)
  1041.       (goto-char start)
  1042.       (reader:skip-whitespace)
  1043.       (while (< (point) end-marker)
  1044.     (setq form (reader:read-from-buffer inside-buf))
  1045.  
  1046.     ;; Evaluate normally - after restoring the current-buffer.
  1047.     (let ((current-buffer (current-buffer)))
  1048.       (set-buffer inside-buf)
  1049.       (setq val (eval form))  ;; *** All the local vars above are visible.
  1050.       ;; Remember current buffer for next time.
  1051.       (setq inside-buf (current-buffer))
  1052.       (set-buffer current-buffer))
  1053.  
  1054.     (if output
  1055.         (let ((standard-output (or output t)))
  1056.           (setq values (cons val values))
  1057.           (if (eq standard-output t)
  1058.           (prin1 val)
  1059.         (princ "\n")
  1060.         (prin1 val)
  1061.         (princ "\n")
  1062.         )))
  1063.  
  1064.     (goto-char 
  1065.      (min (max end-marker (point)) 
  1066.           (progn (reader:skip-whitespace) (point)))))
  1067.       (if (null output)
  1068.       ;; like save-excursion recovery, but only if no error
  1069.       (progn
  1070.         ;; but mark is not restored
  1071.         (set-buffer buf)
  1072.         (goto-char pnt)))
  1073.       ;; return always nil
  1074.       nil)))
  1075.  
  1076. (defun reader:skip-whitespace ()
  1077.   ;; Leave point before the next token, skipping white space and comments.
  1078.   (skip-chars-forward " \t\r\n\f")
  1079.   (while (= (following-char) ?\;)
  1080.     (skip-chars-forward "^\n\r")  ; skip the comment
  1081.     (skip-chars-forward " \t\r\n\f")))
  1082.  
  1083.  
  1084. ;; installing/uninstalling the cl reader
  1085. (defun cl-reader-install ()
  1086.   (interactive)
  1087.   (fset 'read             'reader:read)
  1088.   (fset 'read-from-string     'reader:read-from-string)
  1089.   (fset 'eval-current-buffer     'reader:eval-current-buffer)
  1090.   (fset 'eval-buffer         'reader:eval-buffer)
  1091.   (fset 'eval-region         'reader:eval-region))
  1092.  
  1093. (defun cl-reader-uninstall ()
  1094.   (interactive)
  1095.   (fset 'read                
  1096.     (symbol-function 'reader:original-read))
  1097.   (fset 'read-from-string    
  1098.     (symbol-function 'reader:original-read-from-string))
  1099.   (fset 'eval-current-buffer     
  1100.     (symbol-function 'reader:original-eval-current-buffer))
  1101.   (fset 'eval-buffer         
  1102.     (symbol-function 'reader:original-eval-buffer))
  1103.   (fset 'eval-region         
  1104.     (symbol-function 'reader:original-eval-region)))
  1105.  
  1106. ;; now install the replacement functions:
  1107. (cl-reader-install)
  1108.  
  1109. ; Example:
  1110. ;
  1111. ; After having called `cl-reader-install', this function can be compiled
  1112. ; (M-x elisp-compile-defun) with the syntax used here, but
  1113. ; `eval-last-sexp' and `eval-defun' don't work always (???)
  1114. ;
  1115. ;
  1116. ;(defun test (el list)
  1117. ;  (mapcar #'list
  1118. ;          `(,el  ,@list #\a #\0 #\return )))
  1119. ;
  1120. ; You also can call the reader explicitly as follows: 
  1121. ;
  1122. ;(read (current-buffer)) ;; <- set point after "))", then type C-x C-e   
  1123. ;(defun test (el list)
  1124. ;  (mapcar #'list
  1125. ;          `(,el  ,@list #\a #\0 #\return )))
  1126.  
  1127. ;;; also, the `eval-print-last-sexp' function (LF in *scratch*) seems to work 
  1128. ;;; partially: 
  1129. ;
  1130. ;#'car  <LF>
  1131. ;car
  1132. ;'(#\a #\b) <LF>
  1133. ;(97 98)
  1134. ;
  1135. ;;; but there is an error on that form:
  1136. ;(setq l '(a b c)) <LF>
  1137. ;(a b c)
  1138. ;`(,l ,@l)  <LF>
  1139. ;((a b c) a b c)
  1140. ;)
  1141.  
  1142. ;; end cl-read.el
  1143.